<template>
	<view>
		<textarea class="cont" placeholder-style="color:#CCCCCC" placeholder="简述内容..." maxlength="200" @input="descInput"></textarea>
		<view class="num">{{remnant}}/200</view>
		<view class="imgs">
			<view class="imgItem" v-for="(item,index) in imgList" :key="index" @tap="previewImage(index)">
				<image :src="item"></image>
				<i class="iconfont iconjujue" @tap.stop="clearItem(index)"></i>
			</view>
			<view v-if="imgIndex <= 3" class="clickItem" @tap="upload">
				<i class="iconfont icon-hao"></i>
				<view class="clickFont">{{imgIndex+1}}/4</view>
			</view>
		</view>
		
		<!-- 底部消息 -->
		<view class="item-bottom_content">{{msg}}</view>
		<!-- 提交模块 -->
		<view class="sublitm-wrap" @tap="result">
			<view class="item-submit">提交</view>
		</view>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				imgIndex: 0, //当前将选取的照片数目
				remnant: 0, //当前文本域的字数
				imgList: [], //照片列表
				apply_text: '' ,//当前文本域的内容
			}
		},
		props: {
			msg: String
		},
		methods: {
			result() {
				var data = {};
				data.imgList = this.imgList;
				data.apply_text = this.apply_text;
				this.$emit('submit',data);
			},
			/* 获取文本域的长度及内容 */
			descInput(e) {
				this.remnant = e.detail.cursor;
				this.apply_text = e.detail.value;
				if (this.remnant >= 200) {
					uni.showToast({
						title: '最多只能输入200个字',
						icon: 'none'
					})
				}
			},
			/* 预览图片 */
			previewImage: function(index) {
				var current = index;
				uni.previewImage({
					current: current,
					urls: this.imgList
				})
			},
			/* 删除图片 */
			clearItem(index) {
				this.imgList.splice(index, 1);
				this.imgIndex--;
			},
			upload() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						this.imgList = this.imgList.concat(res.tempFilePaths)
						this.imgIndex++;
					}
				})
			}
		}
	}
</script>

<style>
	.cont {
		color: #333333;
		font-size: 34upx;
		width: calc(100% - 60upx);
		background-color: #FFFFFF;
		padding: 30upx;
	}
	
	.num {
		margin-top: -50rpx;
		position: absolute;
		right: 60rpx;
		color: #CCCCCC;
	}
	
	.imgs {
		padding: 30upx;
		width: calc(100% - 60upx);
		background-color: #FFFFFF;
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}
	
	.imgItem,
	.imgItem image {
		width: 120upx;
		height: 120upx;
		margin-right: 20upx;
		border-radius: 8upx;
	}
	
	.iconjujue {
		color: #FF5A3E;
		position: relative;
		top: -160upx;
		left: 100upx;
	}
	
	.clickItem {
		width: 120upx;
		height: 120upx;
		border: 1upx solid #F6F6F6;
		text-align: center;
		background: #F6F6F6;
		color: #CCCCCC;
		line-height: 1.5;
		border-radius: 8upx;
	}
	
	/* 底部信息 */
	.item-bottom_content {
		padding: 30upx 30upx 124upx;
		color: #999999;
	}
	
	.sublitm-wrap {
		position: fixed;
		padding: 20upx;
		bottom: 0;
		left: 0;
		right: 0;
		background: #F6F6F6;
	}
	
	.item-submit {
		padding: 10upx 0;
		text-align: center;
		font-size: 32upx;
		color: #FFFFFF;
		border-radius: 40upx;
		background: #FF9900;
	}
</style>
